package com.bluebench.bigul.domain;

import java.lang.reflect.InvocationTargetException;

import com.bluebench.bigul.service.DocumentGenerator;
import com.bluebench.bigul.utility.reflection.ReflectionUtil;
import com.itextpdf.text.pdf.PdfContentByte;

public class GraphicInvocation extends Invocation {
	
	

	@Override
	public Object invoke() throws SecurityException, IllegalArgumentException,
			ClassNotFoundException, NoSuchMethodException,
			IllegalAccessException, InvocationTargetException,
			InstantiationException, NoSuchFieldException {
		/*
		 *  TODO : Invoke by reflection the Graphic Object by passing PdfContentByte as Parameter. Obtain the 
		 *  canvas from writer object. 
		 *  
		 */
		String classname = getClassName();
		Class<?> classtype = Class.forName(classname);
		PdfContentByte canvas = DocumentGenerator.getWriter().getDirectContent();
		Class<?>[] constructorArgClassTypes = new Class<?>[]{canvas.getClass()};
		Object[] constructorArgValues = new Object[]{canvas};
		Object returnObj = ReflectionUtil.instantiate(classtype, constructorArgClassTypes, constructorArgValues);
				
		return returnObj;
	}

}
